package com.action;


import com.token .JwtUtil;
import com.vo.ResponseBean;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("/api")
@CrossOrigin("*")
public class LoginAction {

    @RequestMapping("/login")
    public ResponseBean login(String username, String password, HttpServletResponse response){
        if ("admin".equals(username)){
            //产生令牌，并发送到客户端
            String token = JwtUtil.generToken(username,null,null);
            //响应头也存在跨域
            response.addHeader("Access-Control-Expose-Headers","token");
            //发送给客户端
            response.addHeader("token",token);
            return new ResponseBean(200,0,null);
        }
        return new ResponseBean(500,0,null);
    }
}
